<template>
  <el-dialog v-model="visible" title="设置锁屏密码" width="500px">

    <el-form-item>
      <el-input v-model="password" type="password" placeholder="请输入锁屏密码" @keyup.enter="confirm" />
    </el-form-item>

  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, watch } from 'vue'
import { useUserStore } from '@/stores/user'
import { useRouter } from 'vue-router'

const visible = ref(false)
const password = ref('')
const userStore = useUserStore()
const router = useRouter()

const props = defineProps({ modelValue: Boolean })
const emit = defineEmits(['update:modelValue', 'success'])

watch(() => props.modelValue, (val) => {
  visible.value = val
})

watch(visible, (val) => {
  emit('update:modelValue', val)
})

const confirm = () => {
  visible.value = false
  const decryptUser = userStore.decryptUser
  userStore.setEncryptUser({ ...decryptUser, lockpassword: password.value })
  emit('success')
  password.value = ''
  router.push('/tool/lock')
}
</script>

<style></style>
